// BuildingEditor.xaml.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Windows;

using Supremacy.Buildings;
using Supremacy.Economy;

namespace Supremacy.Editor
{
    /// <summary>
    /// Interaction logic for BuildingEditor.xaml
    /// </summary>
    public partial class BuildingEditor : EditorBase
    {
        #region Constructors
        public BuildingEditor()
        {
            InitializeComponent();
        }
        #endregion

        #region Methods
        private void AddBonus(object sender, RoutedEventArgs e)
        {
            BuildingDesign design = base.DataContext as BuildingDesign;

            if (design == null)
                return;

            Bonus? newBonus = NewBonusWindow.GetSelection();

            if (newBonus.HasValue)
            {
                design.Bonuses.Add(newBonus.Value);
                BonusList.Items.Refresh();
            }
        }

        private void DeleteBonus(object sender, RoutedEventArgs e)
        {
            BuildingDesign design = base.DataContext as BuildingDesign;

            if ((design == null) || (BonusList.SelectedIndex < 0))
                return;

            try
            {
                Bonus bonus = (Bonus)BonusList.SelectedItem;
                design.Bonuses.Remove(bonus);
                BonusList.Items.Refresh();
            }
            catch (InvalidCastException) {}
        }
        #endregion
    }
}